package com.business.dashboard.controller;

import com.business.dashboard.utils.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 根路径控制器
 *
 * @author Claude
 * @since 2025-07-07
 */
@Slf4j
@RestController
public class RootController {

    @Value("${spring.application.name:business-dashboard-master}")
    private String applicationName;

    /**
     * 根路径健康检查
     */
    @GetMapping("/")
    public ResultUtil<Map<String, Object>> root() {
        Map<String, Object> info = new HashMap<>();
        info.put("application", applicationName);
        info.put("status", "运行中");
        info.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        info.put("message", "商业管理后台API服务正常运行");
        info.put("endpoints", new String[]{
            "/api/health - 系统健康检查",
            "/api/health/db - 数据库连接测试",
            "/api/admin/auth/login - 管理员登录",
            "/api/admin/stats - 仪表板统计",
            "/api/admin/frontend-users - 用户管理",
            "/api/admin/news - 新闻管理",
            "/api/admin/business-plans - 商业计划管理"
        });
        
        log.info("根路径访问 - 服务状态正常");
        return ResultUtil.success("API服务运行正常", info);
    }

    /**
     * API文档入口
     */
    @GetMapping("/api")
    public ResultUtil<Map<String, Object>> apiInfo() {
        Map<String, Object> info = new HashMap<>();
        info.put("name", "商业管理后台API");
        info.put("version", "1.0.0");
        info.put("description", "为前端管理界面提供数据接口");
        info.put("baseUrl", "/api/admin");
        info.put("authentication", "Session based");
        info.put("healthCheck", "/api/health");
        info.put("documentation", "请参考API_TESTS_OVERVIEW.md");
        
        return ResultUtil.success("API信息", info);
    }

    /**
     * 简单健康检查 (兼容性)
     */
    @GetMapping("/health")
    public ResultUtil<String> simpleHealth() {
        return ResultUtil.success("服务运行正常");
    }
}